<?php namespace Home\Controller;
class StuController extends CommonController
{
	//首页
	public function guanli()
	{
		$cid = $_GET['cid'];
		p($cid);
		
		$data = M()->query("select s.uid,s.username,s.age,s.sex,s.cid from c_five_seven_san as s join c_five_seven_two as t on  s.cid=t.cid where t.cid={$cid}");
		$this->assign('data',$data);
		p($data);
		
		
		$this->display("guanli.php");
	}
	
	//添加同学
	public function add()
	{
		//获取要添加同学的班级
		$cid = $_GET['cid'];
		$data = M()->query("select class from c_five_seven_two where cid={$cid}");
		$this->assign("data",$data);
		
		p($data);
		if(IS_POST){
			$username = $_POST['username'];
			$age = $_POST['age'];
			$sex = $_POST['sex'];
			$rows = M()->exec("insert into c_five_seven_san (username,age,sex,cid) values('{$username}',{$age},'{$sex}','{$cid}')");
			$this->assign("rows",$rows);
			if($rows){
				$this->success("添加成功", "index.php?c=Stu&a=guanli&cid=$cid");
			}else{
				$this->success("添加失败");
			}
		}
		$this->display("add.php");
	}
	//编辑学生
	public function edit()
	{
		$uid = $_GET['uid'];
		$c=$_GET['cid'];
		p($uid);
		$data = M()->query("select * from c_five_seven_san where uid=$uid");
		$t =M()->query("select * from c_five_seven_two where cid=$c");
		$this->assign("data",$data);
		$this->assign("t",$t);
		if(IS_POST){
			$username = $_POST['username'];
			$age = $_POST['age'];
			$sex = $_POST['sex'];
			$rows = M()->exec("update c_five_seven_san set username='{$username}',age='{$age}',sex='{$sex}' where uid=$uid");
			if($rows){
				$this->success("编辑成功", "index.php?c=Stu&a=guanli&cid=$c");
			}else{
				$this->success("添加失败");
			}
		}
		$this->display("edit.php");
	}
	

	
	//删除学生
	public function delete()
	{
		$uid = $_GET['uid'];
		$c=$_GET['cid'];
		p($uid);
		$rows = M()->exec("delete from c_five_seven_san where uid=$uid");
		if($rows){
			$this->success("删除成功", "index.php?c=Stu&a=guanli&cid=$c");
		}else{
			$this->success("删除失败");
			
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
